'use strict';

const { Service } = require('egg');

class MingService extends Service {
  async addGirl(res) {
    try {
      const result = await this.app.mysql.insert('girls', res);
      const insertSuccess = result.affectedRows === 1;
      res.id = result.insertId;
      console.log(res);
      return insertSuccess ? result.insertId : null;
    } catch (error) {
      return null;
    }
  }
  async deleteGirl(id) {
    const result = await this.app.mysql.delete('girls', { id });
    const insertSuccess = result.affectedRows === 1;
    return insertSuccess;
  }
  async updateGirl(res) {
    const result = await this.app.mysql.update('girls', res);
    const insertSuccess = result.affectedRows === 1;
    return insertSuccess;
  }
  async getGirl(id) {
    const result = await this.app.mysql.get(
      'girls',
      { id },
      { columns: ['id', 'name', 'age', 'skills'] }
    );
    return result;
  }
}

module.exports = MingService;
